$(document).ready(function () {
    validateRule();

    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }

    $.validator.setDefaults({
        submitHandler: function (form) {
            console.log('form', form);
            console.log('form params', form.serialize());
            return login();
            return false
        }
    });

    function login() {
        $.modal.loading($("#btnSubmit").data("loading"));
        var params = $("#signupForm").serializeObject();
        console.log('form params', params);
        $.ajax({
            type: "post",
            url: ctx + "login",
            data: params,
            success: function (r) {
                $.modal.closeLoading();
                $.modal.msg(r.msg);
                if (r.code == 0) {
                    // location.href = ctx + 'index';
                    $("#signupForm").reset();
                } else {
                    $.modal.closeLoading();
                    $.modal.msg(r.msg);
                }
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            debug: true,
            rules: {
                peopleName: {
                    required: true
                },
                peopleIdCard: {
                    required: true
                },
                peopleCounty: {
                    required: true
                },
                peopleTownship: {
                    required: true
                },
                peopleVillage: {
                    required: true
                },
                peopleDetailAdress: {
                    required: true
                },
                peopleConnectPhone: {
                    required: true
                },
                peopleJob: {
                    required: true
                },
                peopleBackPeople: {
                    required: true
                },
                peopleCarLicense: {
                    required: true
                },
                peopleCompanyAdressOp: {
                    required: true
                },
                peopleHeathyInfo: {
                    required: true
                },
                peopleLinkAdress: {
                    required: true
                },
                peopleFillTime: {
                    required: true
                }
            },
            messages: {
                peopleName: {
                    required: icon + "请输入您的姓名"
                },
                peopleIdCard: {
                    required: icon + "请输入您的 身份证"
                },
                peopleCity: {
                    required: icon + "请输入您的 市（州）"
                },
                peopleCounty: {
                    required: icon + "请输入您的 县（市、区）"
                },
                peopleTownship: {
                    required: icon + "请输入您的 乡镇（办、场、区）"
                },
                peopleVillage: {
                    required: icon + "请输入您的 社区（村）"
                },
                peopleDetailAdress: {
                    required: icon + "请输入您的 详细地址"
                },
                peopleConnectPhone: {
                    required: icon + "请输入您的 手机号"
                },
                peopleJob: {
                    required: icon + "请输入您的 岗位（工种）"
                },
                peopleBackPeople: {
                    required: icon + "请输入您的 驾驶人/返岗人员"
                },
                peopleCarLicense: {
                    required: icon + "请输入您的 车辆牌照号"
                },
                peopleCompanyAdressOp: {
                    required: icon + "请输入您的 企业所在地县指挥部审核意见"
                },
                peopleHeathyInfo: {
                    required: icon + "请输入您的 居留地健康证明"
                },
                peopleLinkAdress: {
                    required: icon + "请输入您的 健康证明文件地址"
                },
                peopleFillTime: {
                    required: icon + "请输入您的 填报时间"
                }
            },
            submitHandler: function (form) {

                // console.log('form', form);
                // console.log('form params', form.serialize());
                login();
                return false
            },
        })
    }


});